package com.crm.service.impl.contractReviewManager;

import com.crm.dao.mapper.contractReviewManager.ContractReviewMapper;
import com.crm.dao.mapper.customMapper.contractReviewManager.ContractReviewCustomMapper;
import com.crm.model.entity.contractReviewManager.ContractReview;
import com.crm.model.entity.contractReviewManager.ContractReviewExample;
import com.crm.model.qo.contractReviewManager.ContractReviewFormQO;
import com.crm.model.vo.contractReviewManager.ContractCouponVO;
import com.crm.model.vo.contractReviewManager.ContractReviewFormVO;
import com.crm.model.vo.contractReviewManager.ContractReviewVO;
import com.crm.service.contractReviewManager.ContractReviewDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luojie
 * @date 2021/3/30 11:19
 * (客服部)审核管理--合同审核
 */
@Service
public class ContractReviewDbServiceImpl implements ContractReviewDbService {
    @Autowired
    private ContractReviewCustomMapper contractReviewCustomMapper;
    @Autowired
    private ContractReviewMapper contractReviewMapper;

    /**
     * 审核管理--合同审核列表
     * @param contractReviewFormQO ---合同审核列表查询参数
     * @param dateUnit             ---全部、今天、本周、本月查询条件
     * @param orderStr             ---排序
     * @author yincuimei
     * @return
     */
    @Override
    public List<ContractReviewFormVO> selectContractReviewFormVOList(ContractReviewFormQO contractReviewFormQO,Integer dateUnit,String orderStr) {
        return contractReviewCustomMapper.selectContractReviewFormVOList(contractReviewFormQO,dateUnit,orderStr);
    }

    /**
     * 合同详情--审核详情(最新审核记录)
     * @param contractId ---合同ID
     * @author yincuimei
     * @return
     */
    @Override
    public ContractReviewVO selectContractReviewFinally(String contractId) {
        return contractReviewCustomMapper.selectContractReviewFinally(contractId);
    }

    /***
     * @Description:根据合同id获取合同审批列表
     * @Param: contractId
     * @Author: luojie
     * @Date: 2021/3/31 9:49
     */
    @Override
    public List<ContractReview> selectContractReviewListByContractId(String contractId) {
        ContractReviewExample contractReviewExample = new ContractReviewExample();
        ContractReviewExample.Criteria criteria = contractReviewExample.createCriteria();
        criteria.andContractIdEqualTo(contractId);
        contractReviewExample.setOrderByClause("create_tm desc");
        List<ContractReview> contractReviewList = contractReviewMapper.selectByExampleWithBLOBs(contractReviewExample);
        return contractReviewList;
    }

    /***
     * @Description:添加合同审批
     * @Param: contractReview 合同审批对象
     * @Author: luojie
     * @Date: 2021/3/31 10:49
     */
    @Override
    public Boolean addContractReview(ContractReview contractReview) {
        int num = contractReviewMapper.insertSelective(contractReview);
        return num>0;
    }

    /***
     * @Description: 查询客户下的优惠券
     * @Param: customerId 客户id
     * @Author: baijian
     * @Date: 2021/11/15 10:54
     */
    @Override
    public List<ContractCouponVO> contractCouponList(String customerId) {
        return contractReviewCustomMapper.contractCouponList(customerId);
    }
}
